﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using GE_Database_Manager;

namespace UnitTests
{
    [TestClass]
    public class ADRE_UnitTest : Database
    {
        public override bool Process(GE_Database_Manager.Standardized_Wrapper wrapper)
        {
            throw new NotImplementedException();
        }

		public override string Key
		{
			get
			{
				throw new NotImplementedException();
			}
			set
			{
				throw new NotImplementedException();
			}
		}

        public override int ProgressStep { 
            get { return 0; }
            set { } 
        }

        [TestMethod]
        public void ProcessPDF_WithValidFileType_ContainingCorrectValues()
        {
            // expected serial numbers and locations from first two db's
            string db1_sn = "w70336";
            string db1_loc = "judith gap";
            string db2_sn = "w70338";
            string db2_loc = "judith gap";

            // get the actual values from both db's
            Tuple<string, string> db1 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\ADRESXP_100916_101013_V3.00_FullLoad_GearboxKinematics\NameplateInformation.pdf");
            Tuple<string, string> db2 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database2\ADRESXP_100913_194323_V3.00_GearboxKinematics\NameplateInformation.pdf");

            // test for serial number and location equality in db's one and two
            Assert.AreEqual(db1_sn, db1.Item1, true, "Serial number extracted from PDF for first ADRE database is incorrect.");
            Assert.AreEqual(db1_loc, db1.Item2, true, "Location extracted from PDF for first ADRE database is incorrect.");
            Assert.AreEqual(db2_sn, db2.Item1, true, "Serial number extracted from PDF for first ADRE database is incorrect.");
            Assert.AreEqual(db2_loc, db2.Item2, true, "Serial number extracted from PDF for first ADRE database is incorrect.");
        }

        [TestMethod]
        public void ProcessPDF_WithValidFileType_ContainingIncorrectValues()
        {
            // expected serial numbers and locations from first two db's should be null
            string expectedValue = null;

            // get the actual values from both db's
            Tuple<string, string> db1 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Schema\ADRE ConfigDBFile.pdf");
            Tuple<string, string> db2 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Schema\ADRE ConfigDBFile.pdf");

            // test for serial number and location equality in db's one and two
            Assert.AreEqual(expectedValue, db1.Item1, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db1.Item2, true, "Location extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db2.Item1, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db2.Item2, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
        }

        [TestMethod]
        public void ProcessPDF_WithInvalidFilePath()
        {
            // expected serial numbers and locations from first two db's should be null
            string expectedValue = null;

            // get the actual values from both db's
            Tuple<string, string> db1 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\");
            Tuple<string, string> db2 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database2\");

            // test for serial number and location equality in db's one and two
            Assert.AreEqual(expectedValue, db1.Item1, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db1.Item2, true, "Location extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db2.Item1, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db2.Item2, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
        }

        [TestMethod]
        public void ProcessPDF_WithInvalidFileType()
        {
            // expected serial numbers and locations from first two db's should be null
            string expectedValue = null;

            // get the actual values from both db's
            Tuple<string, string> db1 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\ADRESXP_100916_101013_V3.00_FullLoad_GearboxKinematics\Winergy PEAB 4410.3 60Hz Ratio=78.292.xlsm");
            Tuple<string, string> db2 = this.ProcessPDF(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database2\ADRESXP_100913_194323_V3.00_GearboxKinematics\Winergy PEAB 4410.3 60Hz Ratio=78.292.xlsm");

            // test for serial number and location equality in db's one and two
            Assert.AreEqual(expectedValue, db1.Item1, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db1.Item2, true, "Location extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db2.Item1, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
            Assert.AreEqual(expectedValue, db2.Item2, true, "Serial number extracted from PDF for first ADRE database should be NULL.");
        }

        [TestMethod]
        public void ProcessMalfunctionTags_WithValidFileType_ContainingCorrectValues()
        {
            // expected
            string expected = "Broken HSIS Pinion Tooth HSS bearing inner race crack damage";

            // actual
            string actual = this.ProcessMalfunctionTags(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\ADRESXP_100916_101013_V3.00_FullLoad_MalfunctionTag.txt");

            // test
            Assert.AreEqual(expected, actual, true, "String ectracted from MalfunctionTag.txt does not match.");
        }

        [TestMethod]
        public void ProcessMalfunctionTags_WithValidFileType_ContainingIncorrectValues()
        {
            // expected
            string expected = null;

            // actual
            string actual = this.ProcessMalfunctionTags(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\ADRESXP_100916_101013_V3.00_FullLoad\ADRESXP_100916_101013_V3.00_FullLoad\Notes\Comments.txt");

            // test
            Assert.AreEqual(expected, actual, true, "String should return null if file name doesn't contain \"MalfunctionTag\".");
        }

        [TestMethod]
        public void ProcessMalfunctionTags_WithInvalidFileType()
        {
            // expected
            string expected = null;

            // actual
            string actual = this.ProcessMalfunctionTags(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\ADRESXP_100916_101013_V3.00_FullLoad_PicturesOfDamage.pdf");

            // test
            Assert.AreEqual(expected, actual, true, "String should return null if incorrect file type is selected.");
        }

        [TestMethod]
        public void ProcessExcel_WithValidFileType_ContainingCorrectValues()
        {
            // expected
            Dictionary<string, string> expectedD = new Dictionary<string, string>()
            {
                {"gearbox_make", "Winergy"},
                {"type", "Planetary"},
                {"sun_tooth_count", "22"},
                {"fixed", "Yes"},
                {"ring_tooth_count", "113"},
                {"planet_count", "3"},
                {"planet_tooth_count", "45"},
                {"s2 type", "Parallel"},
                {"s2 gear_tooth_count", "89"},
                {"s2 pinion_tooth_count", "22"},
                {"s3 type", "Parallel"},
                {"s3 gear_tooth_count", "82"},
                {"s3 pinion_tooth_count", "26"}
            };
            List<string> expectedL = expectedD.Values.ToList();
            expectedL.Sort();
            string expectedS = string.Join(",", expectedL.ToArray());
           
            // actual
            Dictionary<string, string> actualD = this.ProcessExcel(@"C:\Users\avant\Documents\UNR Data Analytics\ADRE Data\database1\ADRESXP_100916_101013_V3.00_FullLoad_GearboxKinematics\Winergy PEAB 4410.3 60Hz Ratio=78.292.xlsm");
            List<string> actualL = actualD.Values.ToList();
            actualL.Sort();
            string actualS = string.Join(",", actualL.ToArray());
           
            // test
            Assert.AreEqual(expectedS, actualS, true, "Expected values form Excel sheet do not match.");
        }
    }
}
